package com.chentf.spring.annotation;

import com.chentf.spring.annotation.bean.Person;
import com.chentf.spring.annotation.config.PersonConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * Hello world!
 *
 */
public class App {
    public static void main( String[] args ) {
//        ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
//        Person person = (Person)context.getBean("person");
//        System.out.println(person.toString());

        ApplicationContext context = new AnnotationConfigApplicationContext(PersonConfig.class);
        Person person = (Person)context.getBean("person");
        System.out.println(person.toString());

        // Person这个类型的组件在IOC容器中的名字是什么呢？
        final String[] beanNamesForType = context.getBeanNamesForType(Person.class);
        for (String name : beanNamesForType) {
            System.out.println(name);
        }
    }
}
